#ifndef _EVENT_H
#define _EVENT_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include "doevent.h"

int eventflag; // this for the event of one page

void *mouse_event(void *flag)
{
	int fd = open("/dev/ubuntu_event", O_RDWR);
	if (-1 == fd)
	{
		perror("open error");
		return NULL;
	}
	//读取文件信息
	struct input_event ev;
	int x = -1, y = -1;
	int ret;
	int l = 0;

	while (1)
	{

		read(fd, &ev, sizeof(ev));
		//分析读取到的事件
		if (ev.type == EV_ABS && ev.code == ABS_X && l == 0)
		{
			//描述横坐标的事件
			x = ev.value;
			l = 1;
		}

		if (ev.type == EV_ABS && ev.code == ABS_Y && l == 1)
		{
			//描述纵坐标的事件
			y = ev.value;
			l = 2;
		}
		if (x >= 0 && y >= 0 && l == 2)
		{

			int *a = flag;
			// a : page    eventflag : event of one page

			// to deal the click event
			do_mouse_event(x, y, a, &eventflag);
			x = -1;
			y = -1;
			l = 0;
		}
	}

	close(fd);
	return NULL;
}

#endif